package listener;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JTextField;
import config.SocketConfig;
import ui.SetUI;

/**
 * 实现接口ActionListener
 * 
 * @author wj
 * 
 */
public class SetListener implements ActionListener {
	/**
	 * 定义属性 重写构造方法
	 */
	private JTextField ipAddress;
	private JTextField socketPort;
	private SetUI setUI;
	private JButton jb1;

	public SetListener(SetUI setUI) {
		this.setUI = setUI;
		this.ipAddress = setUI.ipAddress;
		this.socketPort = setUI.socketPort;
		this.jb1 = setUI.jb1;
	}

	/**
	 * 对输入的信息进行判断 输出结果
	 */
	public void actionPerformed(ActionEvent e) {
		if (e.getSource() == jb1) {
			SocketConfig.ipAddress = ipAddress.getText();
			SocketConfig.socketPort = Integer.parseInt(socketPort.getText());
		} 
		setUI.setVisible(false);
	}
}
